package top.hepingan.java.service.Impl.service.impl;

import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import org.springframework.beans.factory.annotation.Autowired;
import top.hepingan.java.entity.Bottle;
import top.hepingan.java.entity.Res.ReplRes;
import top.hepingan.java.entity.Dto.pickupRes;
import top.hepingan.java.entity.Pickup;
import top.hepingan.java.mapper.BottleMapper;
import top.hepingan.java.mapper.PickupMapper;

import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import org.springframework.stereotype.Service;
import top.hepingan.java.service.Impl.service.IPickupService;

import java.util.Collections;
import java.util.List;

/**
 * <p>
 * 漂流瓶捞取记录表 服务实现类
 * </p>
 *
 * @author author
 * @since 2025-10-28
 */
@Service
public class PickupServiceImpl extends ServiceImpl<PickupMapper, Pickup> implements IPickupService {
@Autowired
private BottleMapper bottleMapper;;
    @Override
    public List<pickupRes> getHistoryBottle(Long userId) {
        //查询捞取表。拿出所以捞取到的漂流瓶ID

        List<Pickup> pickups = this.list(new LambdaQueryWrapper<Pickup>().eq(Pickup::getPickerId, userId));
        //拿取到与我有关的漂流瓶
        List<Long> bottleIds = pickups.stream().map(Pickup::getBottleId).toList();
        if ( bottleIds.isEmpty()) {
            return Collections.emptyList();
        }
        List<Bottle> bottles = bottleMapper.selectBatchIds(bottleIds);

        List<pickupRes> res = bottles.stream().map(bottle -> {
            pickupRes resa = new pickupRes();
            resa.setId(bottle.getId());
            resa.setUserId(bottle.getUserId());
            resa.setContent(bottle.getContent());
            resa.setType(bottle.getType());
            resa.setLikeCount(bottle.getLikeCount());
            resa.setStatus(bottle.getStatus());
            resa.setCreateTime(bottle.getCreateTime());
            return resa;
        }).toList();
        return res;
    }

    @Override
    public List<ReplRes> lookBottle(Pickup pickup) {
        //这里传来的一定是漂流瓶除开自己本身的
        LambdaQueryWrapper<Pickup> wrapper = new LambdaQueryWrapper<>();

        return List.of();
    }
}
